/**
 * @author wangning 20180414
 * 安全主体责任排行榜
 */
import { Component, OnInit } from '@angular/core';
import { HttpServcie } from '../../../../service/http.service';

@Component({
  selector: 'duty-ranking-list',
  templateUrl: './duty-ranking-list.html',
  styleUrls: ['./duty-ranking-list.scss']
})

export class DutyRankingList implements OnInit {
  data;
  virtualData_1;
  virtualData_2;
  WBRank = [];//维保排行榜
  WYRank = [];//物业单位排行榜
  GLYRank = [];//电梯安全管理员排行榜
  WBYRank = [];//维保员排行榜
  constructor(
    private httpServcie: HttpServcie,
  ) {
   }

  ngOnInit() {
    // this.virtualData_1 = {
    //   rankings:[
    //     {userName:'ha',ranking:'一',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'二',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'三',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'四',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'五',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'六',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'七',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'八',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'九',partyName:'afafaf',empiricValue:'1000'},
    //     {userName:'ha',ranking:'十',partyName:'afafaf',empiricValue:'1000'},
    //   ]
    // }
    // this.virtualData_2 = {
    //   rankings:[
    //     {userName:'ha',ranking:'一',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'二',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'三',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'四',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'五',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'六',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'七',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'八',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'九',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //     {userName:'ha',ranking:'十',partyName:'afafaf',empiricValue:'1000',grade:'1',achieve:'100'},
    //   ]
    // }
    // this.WBRank = this.virtualData_1.rankings;
    // this.WYRank = this.virtualData_1.rankings;
    // this.GLYRank = this.virtualData_2.rankings;
    // this.WBYRank = this.virtualData_2.rankings;
    /*this.ranks();*/
    this.findRanks();
  }

  /**
   * 获取安全主体责任排行表
   */
  findRanks() {
    let partyId = JSON.parse(window.localStorage.getItem("user")).partyId;
    // 获取数据
    this.httpServcie.findRanks({"partyId": partyId}).subscribe(data => {
      if (data.status==200) {
        this.WBRank = data.data.mainRank;
        this.WYRank = data.data.userRank;
        this.WBYRank = data.data.mainUserRank;
        this.GLYRank = data.data.userUserRank;
      }
    })
  }

  /**
   * 之前同事所写，注释掉，没有用
   */
  //各类前十名排行榜
  ranks(){
    // 维保单位
    this.httpServcie.ranks({type:'1'}).subscribe(data => {
      if (data.data) {
          let ret = data.data;
          this.WBRank = ret.rankings;
      }
    })
    // 物业单位
    this.httpServcie.ranks({type:'2'}).subscribe(data => {
      if (data.data) {
          let ret = data.data;
          this.WYRank = ret.rankings;
      }
    })
    // 电梯安全管理员
    this.httpServcie.ranks({type:'3'}).subscribe(data => {
      if (data.data) {
          let ret = data.data;
          this.GLYRank = ret.rankings;
      }
    })
    // 维保员
    this.httpServcie.ranks({type:'4'}).subscribe(data => {
      if (data.data) {
          let ret = data.data;
          this.WBYRank = ret.rankings;
      }
    })
  }
}
